package 力扣热题100;

import java.util.ArrayList;
import java.util.List;

public class LeetCode21 {
    List<List<Integer>> list=new ArrayList<>();
    List<Integer>list1=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        dfs(nums,list1);
        return list;
    }

    private void dfs(int[] nums, List<Integer> list1) {
        if(list1.size()== nums.length){
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if(list1.contains(nums[i])){
                continue;
            }
            list1.add(nums[i]);
            dfs(nums,list1);
            list1.remove(list1.size()-1);
        }
    }

    public static void main(String[] args) {
        LeetCode21 leetcode21=new LeetCode21();
        leetcode21.permute(new int[]{1,2,3});
    }
}
